home *** CD-ROM | disk | FTP | other *** search
- MODULE 'dos/dos','dos/dostags','dos/dosextens','utility/tagitem','exec/nodes'
- MODULE 'exec/ports','exec/memory'
-
- PROC main()
- -> message for interprocess communication
- DEF message:PTR TO MN
- -> port of main process
- DEF port:PTR TO MP
- -> pointer to the thread process
- DEF mythread:PTR TO Process
-
- -> port to talk with thread
- IF port:=CreateMsgPort()
-
- -> allocate message
- IF message:=AllocVec(SIZEOF_MN,MEMF_CLEAR OR MEMF_PUBLIC)
-
- -> fill in message node
- message::LN.Type:=NT_MESSAGE
- message.Length:=SIZEOF_MN
- message.ReplyPort:=port
-
- -> create a thread process
- IF mythread:=CreateNewProc(
- [
- NP_Entry,&thread, -> where the thread process begins
- NP_Name,'MyThread', -> the thread process name
- TAG_DONE
- ])
-
- -> send the thread a startup message
- PutMsg(mythread.MsgPort,message)
-
- /* main program here */
-
- -> wait for the threads' death
- WaitPort(port)
-
- ENDIF
- FreeVec(message)
- ENDIF
- DeleteMsgPort(port)
- ENDIF
- ENDPROC
-
- PROC thread()
- -> pointer to this process
- DEF thisthread:PTR TO Process
- -> pointer to the received message
- DEF message:PTR TO MN
-
- -> find out about ourselves
- thisthread:=FindTask(0)
-
- -> wait for the startup message (sent by the main process)
- WaitPort(thisthread.MsgPort)
-
- -> get the startup message
- message:=GetMsg(thisthread.MsgPort)
-
- /* thread program begins here */
-
- -> useless program, just waits a second
- WriteF('Hello, I\am a newbie thread. It\as nice to be here.\n')
- Delay(50)
-
- /* thread program ends here */
-
- -> make sure there is no taskswitching after we replied the message
- Forbid()
-
- -> reply to main process
- ReplyMsg(message)
-
- -> thread dies here
- ENDPROC
-